package com.dream.keigezhushou.Activity.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dream.keigezhushou.Activity.bean.GameBean;
import com.dream.keigezhushou.Activity.view.CircleImageView;
import com.dream.keigezhushou.R;
import com.squareup.okhttp.Request;
import com.zhy.autolayout.utils.AutoUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.BitmapCallback;

import java.util.List;

/**
 *
 * adapter的创建
 */

public class GameEvaluateAdapter extends RecyclerView.Adapter<GameEvaluateAdapter.MyViewHolder>{

    private Context mContext;

    private List<GameBean.CommentsBean> commentsList;

    public GameEvaluateAdapter(Context context,List<GameBean.CommentsBean> commentsList) {
        this.mContext = context;
        this.commentsList = commentsList;

    }

    //定义item点击的接口
    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    private OnItemClickListener mOnItemClickListener;

    //点击的监听
    public OnItemClickListener getmOnItemClickListener() {
        return mOnItemClickListener;
    }

    //设置点击监听
    public void setmOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }


    @Override
    public int getItemCount() {
        return commentsList.size();
    }

    //绑定viewholder
    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {

        holder.itemView.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {

                if (mOnItemClickListener != null){
                    mOnItemClickListener.onItemClick(v,position);
                }
            }
        });

        holder.tvUserNick.setText(commentsList.get(position).getNickname());
        holder.tvDate.setText(commentsList.get(position).getDateline());
        holder.tvDescribe.setText(commentsList.get(position).getContent());

        String url = commentsList.get(position).getAvatar();


    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_evaluate_item,parent,false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{


        CircleImageView ivUserPic;
        TextView tvUserNick;
        TextView tvDate;
        TextView tvDescribe;

        public MyViewHolder(View itemView){
            super(itemView);

            ivUserPic = (CircleImageView)itemView.findViewById(R.id.iv_user_pic);
            tvUserNick = (TextView)itemView.findViewById(R.id.tv_user_nick);
            tvDate = (TextView)itemView.findViewById(R.id.tv_date);
            tvDescribe = (TextView)itemView.findViewById(R.id.tv_describe);

            AutoUtils.autoSize(itemView);


        }

    }
}
